package com.atech.ace.business;

import java.util.List;

import javax.ejb.Stateless;

import com.atech.ace.business.client.UserAdministrationRemote;
import com.atech.ace.dao.UserHome;
import com.atech.ace.entity.User;

/**
 * Session Bean implementation class UserAdministration
 */
@Stateless
public class UserAdministration implements UserAdministrationRemote, UserAdministrationLocal {

    /**
     * Default constructor. 
     */
    public UserAdministration() {
        // TODO Auto-generated constructor stub
    }
    
    public void registerUser(User user)
    {
    	UserHome manager = new UserHome();
    	manager.persist(user);
    }
    
    public void updateUser(User user)
    {
    	UserHome manager = new UserHome();
    	manager.attachDirty(user);
    }
    
    public User getUser(String username)
    {
    	UserHome manager = new UserHome();
    	User u = new User();
    	u.setUserName(username);
    	List users = manager.findByExample(u);
    	u = (User) users.get(0);
    	return u;
    }
    
    public User authenticate(User user)
    {
    	UserHome manager = new UserHome();
    	user = manager.findByUserAndPassword(user);
    	
    	return user;
    }

}
